.TH std::basic_stringbuf::swap 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_stringbuf::swap \- std::basic_stringbuf::swap

.SH Synopsis
   void swap( basic_stringbuf& rhs );                            \fI(since C++11)\fP
                                                                 \fI(until C++20)\fP
   void swap( basic_stringbuf& rhs ) noexcept(/* see below */);  \fI(since C++20)\fP

   Swaps the state and the contents of *this and rhs.

   The behavior is undefined if Allocator does not propagate on swap and  \fI(since C++11)\fP
   the allocators of *this and other are unequal.

.SH Parameters

   rhs - another basic_stringbuf

.SH Return value

   \fI(none)\fP

.SH Exceptions

                                                                                 (since
   May throw implementation-defined exceptions.                                  C++11)
                                                                                 (until
                                                                                 C++20)
   noexcept specification:                                                       (since
   noexcept(std::allocator_traits<Allocator>::propagate_on_container_swap::value C++20)
   || std::allocator_traits<Allocator>::is_always_equal::value)

.SH Notes

   This function is called automatically when swapping std::stringstream objects. It is
   rarely necessary to call it directly.

.SH Example


// Run this code

 #include <iomanip>
 #include <iostream>
 #include <sstream>
 #include <string>

 int main()
 {
     std::istringstream one("one");
     std::ostringstream two("two");

     std::cout << "Before swap: one = " << std::quoted(one.str())
               << ", two = " << std::quoted(two.str()) << ".\\n";

     one.rdbuf()->swap(*two.rdbuf());

     std::cout << "After  swap: one = " << std::quoted(one.str())
               << ", two = " << std::quoted(two.str()) << ".\\n";
 }

.SH Output:

 Before swap: one = "one", two = "two".
 After  swap: one = "two", two = "one".

.SH See also

   constructor   constructs a basic_stringbuf object
                 \fI(public member function)\fP
   swap          swaps two string streams
   \fI(C++11)\fP       \fI\fI(public member\fP function of\fP
                 std::basic_stringstream<CharT,Traits,Allocator>)

.SH Category:
     * conditionally noexcept
